package com.loma.common.model.store

import androidx.annotation.Keep
import com.tencent.mmkv.MMKV

/**
 * Created by xiaojianjun on 2019-11-24.
 */
@Keep
object UserInfoStore {

    private const val KEY_USER_INFO = "userInfo"

    fun isLogin(): Boolean {

        return MMKV.defaultMMKV().containsKey(KEY_USER_INFO)
    }



    fun clearUserInfo() {
        MMKV.defaultMMKV().removeValueForKey("TOKEN")
        MMKV.defaultMMKV().removeValueForKey(KEY_USER_INFO)

    }

    fun setToken(token: String) {
        MMKV.defaultMMKV().encode("TOKEN", token)

    }

    fun getToken() :String{
     return   MMKV.defaultMMKV().decodeString("TOKEN")

    }

    fun setUsername(s: String) {
        MMKV.defaultMMKV().encode("username", s)
    }

    fun setPassword(s: String) {
        MMKV.defaultMMKV().encode("password", s)
    }

    fun getUsername(): String {
        return MMKV.defaultMMKV().decodeString("username", "")
    }

    fun getPassword(): String {
        return MMKV.defaultMMKV().decodeString("password", "")
    }

    fun isFirstLogin(): Boolean {
        return MMKV.defaultMMKV().decodeBool("isFirstLogin", true)
    }

    fun setNoFirstLogin() {
        MMKV.defaultMMKV().encode("isFirstLogin", false)
    }
}